package com.example.ui_demo_widget1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ListViewActivity extends AppCompatActivity {
    private List<Map<String ,Object>> data;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);
        initData();
        ListView lvsimple = findViewById(R.id.lv_simple);
        SimpleAdapter adapter=new SimpleAdapter(
                this,data,R.layout.listview_simple_item,
                new String[]{"id","name","wallet"},
                new int[]{R.id.tv_simple_id,R.id.tv_simple_name,R.id.tv_simple_wallet}
        );
        lvsimple.setAdapter(adapter);
    }
    private void initData(){
        data = new ArrayList<Map<String,Object>>();
        HashMap<String ,Object> item=new HashMap<>();
        item.put("id",1);
        item.put("name","wangrc");
        item.put("wallet",1700);
        data.add(item);
        HashMap<String ,Object> item2=new HashMap<>();
        item2.put("id",1);
        item2.put("name","wangrc");
        item2.put("wallet",1700);
        data.add(item2);
    }
}